/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Rada.Html;

import Rada.RObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


/**
 *
 * @author Miguel
 */
public class Table extends RObject{
    public int border;
    public int cellspacing, cellpadding;
    public String align;
    List<Tr> rows;
    public Tr TrCurrent;
    public Table(){
        super();
        border=1;
        cellspacing=0;
        cellpadding=0;
        align=null;
        rows = new ArrayList<Tr>();
        TrCurrent =null;
    }
    public void addRow(){
        TrCurrent = new Tr();
        rows.add(TrCurrent);
    }
    public void add(RObject value){
        if (TrCurrent==null) addRow();
        TrCurrent.add(value);
    }
    public void addColSpan(RObject value, int span){
        if (TrCurrent==null) addRow();
        TrCurrent.addColSpan(value, span);
    }
    public void addRowSpan(RObject value, int span){
        if (TrCurrent==null) addRow();
        TrCurrent.addRowSpan(value, span);
    }
    public void addSpan(RObject value, int colspan, int rowspan){
        if (TrCurrent==null) addRow();
        TrCurrent.addSpan(value, colspan, rowspan);
    }
    @Override
    public String show(){
        html="";
        html+="<table border='"+border+"'";
        html+=" cellpadding="+cellpadding;
        html+=" cellspacing="+cellspacing;
        if (align!=null) html+=" align="+align;
        if (background!=null) html+=" background="+background;
        html+=getProperties();
        html+=">";
        Iterator it;
        it = rows.listIterator();
        while (it.hasNext()){
            html+=((Tr)it.next()).show();
        }
        html+="</table>";
        return html;
    }

}
